<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2022/5/26
 * Time: 下午3:02
 */

namespace app\api\controller\v32;

use app\api\controller\v13\Auth2;
use app\common\cachemodel\GoddessArea as GoddessAreaModel;
use app\common\cachemodel\GoddessBaseInfo;
use think\response\Json;

/**
 * Class GoddessArea
 * @package app\api\controller\v32
 */
class GoddessArea extends Auth2
{
    /**
     * 女神专区
     * @return Json
     * @throws \Exception
     */
    public function index()
    {
        $page = input('page/d', 1);
        $limit = input('limit/d', 10);
        $uid = $this->user ? (int)$this->user['id'] : null;

        $goddessInfo = (new GoddessBaseInfo())->getInfo(['nickname', 'avatar', 'notice_img2', 'target2', 'link2']);

        $goddessArea = (new GoddessAreaModel())->getThemeData($uid, $goddessInfo, $page, $limit);

        //若未开启苹果审核且有公告，则将公告追加进动态列表中
        if (($page === 1) && !$this->is_apple_check && $goddessInfo['notice_img2'])
        {
            $notice = [
                'type' => 5,
                'thumb' => $goddessInfo['notice_img2'] ?? '',
                'target' => $goddessInfo['target2'] ?? '',
                'link' => $goddessInfo['link2'] ?? '',
            ];
            array_unshift($goddessArea['data'], $notice);
        }

        return show(config('code.success'), '专区信息', $goddessArea);
    }
}
